import { createSlice, PayloadAction } from '@reduxjs/toolkit'

export type CounterState = {
  count: number
}

const initialState: CounterState = {
  count: 0
}

const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: {
    add(state, action: PayloadAction<number>) {
      state.count += action.payload
    }
  }
})

export const { add } = counterSlice.actions
export default counterSlice.reducer
